package cn.xfdzx.android.apps.shop.presenter;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.AddAddressBeen;
import cn.xfdzx.android.apps.shop.bean.XFDConfirmOrderBeen;
import cn.xfdzx.android.apps.shop.contract.AddAddressContract;
import cn.xfdzx.android.apps.shop.contract.XFDConfirmOrderContract;
import cn.xfdzx.android.apps.shop.model.AddAddressModel;
import cn.xfdzx.android.apps.shop.model.XFDConfirmOrderModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author azheng
 * @date 2018/6/4.
 * Description：
 */
public class XFDConfirmOrderPresenter extends BasePresenter<XFDConfirmOrderContract.View> implements XFDConfirmOrderContract.Presenter {

    private XFDConfirmOrderContract.Model model;

    public XFDConfirmOrderPresenter() {
        model = new XFDConfirmOrderModel();
    }



    @Override
    public void xfdConfirmOrder(String orderKey, String address_id) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.xfdConfirmOrder(orderKey, address_id)
                .compose(RxScheduler.<XFDConfirmOrderBeen>Flo_io_main())
                .as(mView.<XFDConfirmOrderBeen>bindAutoDispose())
                .subscribe(new Consumer<XFDConfirmOrderBeen>() {
                    @Override
                    public void accept(XFDConfirmOrderBeen bean) throws Exception {
                        mView.onXfdConfirmOrderSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
